package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.Position;
import com.example.mapper.PositionMapper;
import com.example.service.IPositionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 岗位表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-03-28
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements IPositionService {

    @Autowired
    private PositionMapper pm;

    @Override
    public PageInfo<Position> getPositionPageInfo(Integer pageNum, Integer pageSize, String keyword, Integer enabled, Date start, Date end) {
        PageHelper.startPage(pageNum,pageSize);
        List<Position> list = baseMapper.selectPageInfo(keyword,enabled,start,end);
        return new PageInfo<>(list);
    }

    @Override
    public Boolean hasSomeNamePosition(Integer id, String name) {
        QueryWrapper<Position> wrapper = new QueryWrapper<>();
        wrapper.eq("name",name)
                .notIn(id!=null,"id",id);
        Long aLong = baseMapper.selectCount(wrapper);
        return aLong > 0;
    }

    @Override
    public Boolean hasSomeCodePosition(Integer id, String code) {
        QueryWrapper<Position> wrapper = new QueryWrapper<>();
        wrapper.eq("code",code)
                .notIn(id!=null,"id",id);
        Long aLong = baseMapper.selectCount(wrapper);
        return aLong > 0;
    }

    @Override
    public List<Map<String, Object>> selectDeptByEmp() {
        return pm.selectDeptByEmpId();
    }

}
